package com.example.hotbar;

import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class UpdateBarCount extends Activity implements OnClickListener  {

	EditText  etUpSqlName, etUpSqlLocation, etUpSqlBarCount;
	Button sqlUpdate;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_update_bar_count);
		
		sqlUpdate = (Button) findViewById(R.id.UpdateBarCount);
		etUpSqlName = (EditText) findViewById(R.id.etUpdateBarName);
		etUpSqlLocation = (EditText) findViewById(R.id.etUpdateLocation);
		etUpSqlBarCount = (EditText) findViewById(R.id.etBarCount);
		
		sqlUpdate.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.update_bar_count, menu);
		return true;
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		switch (arg0.getId()){
		
		case R.id.UpdateBarCount:
			try{
				String barName = etUpSqlName.getText().toString();
				String barLocation = etUpSqlLocation.getText().toString();
				String barCount = etUpSqlBarCount.getText().toString();
				
				//Integer IntegerCount = Integer.parseInt(barCount);
				
				HotBarDB update = new HotBarDB(UpdateBarCount.this);
				update.open();
				
				update.updateBarCountDB(barName,barLocation,barCount );
				
				update.close();
				
				Dialog d = new Dialog(this);
				d.setTitle("Completed");
				TextView tv = new TextView(this);
				tv.setText("Success");
				d.setContentView(tv);
				d.show();
				
				Intent i = new Intent(UpdateBarCount.this, MainActivity.class);
				
				startActivity(i);
				
			}catch (Exception e){
				//didItWork = false;
				String error = e.toString();
				Dialog d = new Dialog(this);
				d.setTitle("Dang IT!");
				TextView tv = new TextView(this);
				tv.setText(error);
				d.setContentView(tv);
				d.show();
		}
			break;
			
	}

	}

}
